#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

//查看进程地址空间

int g_unval;
int g_val = 100;
int main(int argc, char *argv[], char *env[])
{
    const char *str = "hello world";//字符常量区
    //字面常量
    // 10;
    // 'a';
    printf("code addr:%p\n",main);
    printf("init global addr:%p\n",&g_val);
    printf("uninit global addr:%p\n",&g_unval);
    
    static int test = 10;//static修饰局部变量：将该变量开辟在全局数据区
    char *heap_men = (char*)malloc(10);
    char *heap_men1 = (char*)malloc(10);
    char *heap_men2 = (char*)malloc(10);
    char *heap_men3 = (char*)malloc(10);
    printf("heap addr:%p\n",heap_men);//打印堆区的地址
    printf("heap addr:%p\n",heap_men1);//打印堆区的地址
    printf("heap addr:%p\n",heap_men2);//打印堆区的地址
    printf("heap addr:%p\n",heap_men3);//打印堆区的地址

    printf("test stack addr:%p\n",&test);//打印栈区的地址
    printf("stack addr:%p\n",&heap_men);//打印栈区的地址
    printf("stack addr:%p\n",&heap_men1);//打印栈区的地址
    printf("stack addr:%p\n",&heap_men2);//打印栈区的地址
    printf("stack addr:%p\n",&heap_men3);//打印栈区的地址

    printf("read only string addr:%p\n",str);

    int i = 0;
    while (i < argc)
    {
        printf("argv[%d]:%p\n", i, argv[i]);
        i++;
    }
    
    i = 0;
    while (env[i])
    {
        printf("env[%d]:%p\n", i, env[i]);
        i++;
    }

    return 0;
}
